<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Danh sách hệ số điểm sản phẩm</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
             <div class="panel-heading">
                 <div class="row">
                     <div class="col-lg-3">
                        <a class="" href="<?php echo $this->url(array("action"=>"add")) ?>">Thêm hệ số điểm cho sản phẩm</a>
                     </div>                      
               </div>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-3">
                        
                    </div>
                </div>
                <div class="table-reponsive">
                    <div id="jqxgrid">
                        
                    </div>
                </div>
        </div>
    </div>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'id',type:'int'},
                    { name: 'area_name', type: 'string' },     
                    { name: 'agent_name', type: 'string' },
                    { name:'product_name',type:'string'},
                    { name:'province_name',type:'string'},
                    { name:'district_name',type:'string'},
                    { name:'factor',type: 'string'},
                    { name:'from_date',type:'date'},
                    {name:'to_date',type:'date'},
                    {name:'event',type:'string'}
                ],
                url:'<?php echo $this->baseUrl() ?>/admin/areaagentproduct/service',               
                sortdirection: 'asc'
            };
         var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxDataTable(
            {
                source: dataAdapter,
                theme:'bootstrap',
                pageable: true,
                altRows: true,
                filterable: true,
                sortable: true,
                width: '100%',
              
                
                ready: function () {
                    $("#jqxgrid").jqxDataTable('hideColumn', 'id');
                },
                columns: [ 
                  { text: 'id',hidden:true,dataField:'id',filterable:false,cellsalgin:'right',width:0},
                  { text: 'Tên vùng',hidden:false,dataField:'area_name',cellsalgin:'right',width:'12%'},
                  { text: 'Tỉnh thành',hidden:false,dataField:'province_name',cellsalgin:'right',width:'12%'},
                  { text: 'Quận huyện',hidden:false,dataField:'district_name',cellsalgin:'right',width:'10%'},
                  { text: 'Tên đại lý/Cửa hàng',hidden:false,dataField:'agent_name',cellsalgin:'right',width:'15%'},
                  { text: 'Sản phẩm',hidden:false,dataField:'product_name',cellsalgin:'right',width:'15%'},                 
                  { text: 'Hệ số',hidden:false,dataField:'factor',cellsalgin:'right',width:'5%'},        
                  { text: 'Sự kiện',columnType: 'checkbox',editable: false, dataField: 'event', width: '5%'}, 
                  { text: 'Từ ngày',hidden:false,dataField:'from_date',cellsalign:'right',width:'8%',cellsFormat:'dd/MM/yyyy'},
                  { text: 'Đến ngày',hidden:false,dataField:'to_date',cellsalign:'right', width:'8%',cellsFormat:'dd/MM/yyyy'},
                  {
                    text: 'Xoá', cellsAlign: 'center', align: "center", width:'5%' ,columnType: 'none', editable: false, sortable: false, dataField: null, cellsRenderer: function (row, column, value) {
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxDataTable('getRows');
                          if(dataRecord[editrow]['id']===null){
                              url="";
                              return url;
                          } else {
                               var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-trash-o fa-lg'";
                               url = url + "href='#' onclick='return jsdelete("+dataRecord[editrow]['id']+")'></a></div>";
                               return url;
                          }
                      }
                  },
                  
                  {
                    text: 'Sửa', cellsAlign: 'center', align: "center", width:'5%' ,columnType: 'none', editable: false, sortable: false, dataField: null, cellsRenderer: function (row, column, value) {
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxDataTable('getRows');
                          if(dataRecord[editrow]['id']===null){
                              url="";
                              return url;
                          } else {
                               var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                               url = url + "href='<?php echo $this->baseUrl()?>/admin/areaagentproduct/edit/id/"+dataRecord[editrow]['id']+"'></a></div>";
                               return url;
                          }
                      }
                  }
                ]
            });
           
        });
    </script>
    <script type="text/javascript">
        function jsdelete(id)
        {
            
                    bootbox.confirm("Bạn có chắc muốn xoá hệ số điểm của sản phẩm này không?",
                    function(result){
                        if(result == true)
                        {
                           return window.location = "<?php echo $this->baseUrl() ?>/admin/areaagentproduct/delete/id/"+id;
                        }
                    });
                
            
        }
    </script>